<?php
declare (strict_types = 1);
namespace adminmatrix\server\app\lists;

trait ListsPagerTrait
{
    protected bool $isPager = false;
    /**
     * @notes 初始化分页
     * @return void
     */
    public function initPage()
    {
        $this->pageType     =   (int) $this->request->get('pageType', '0');

        if ($this->pageType)
        {
            $this->pageNo       =   1;
            $this->pageSize     =   25000;
        }else{
            $this->pageNo       =   (int) $this->request->get('current', 1);
            $this->pageSize     =   (int) $this->request->get('pageSize', 10);
        }

        $this->limitOffset  =   ($this->pageNo - 1) * $this->pageSize;
        $this->limitLength  =   $this->pageSize;
        $parentClass = @class_parents($this->model);
        if (isset($parentClass['adminmatrix\server\app\model\BaseModel']) && $this->isPager)
        {
            $this->model->limit($this->limitOffset , $this->limitLength);
        }
    }
}